package client;

import core.Food;
import core.MyFrame;
import core.MySnake;
import util.ImageUtil;
import java.awt.*;
import java.awt.event.KeyEvent;

public class Play extends MyFrame {

    private static final long serialVersionUID = -3641221053272056036L;

    public MySnake mySnake = new MySnake(100,100);
    public Food food = new Food();

    Image background = ImageUtil.images.get("background");

    @Override
    public void keyPressed(KeyEvent e) {
        super.keyPressed(e);
        mySnake.keyPressed(e);
    }

    @Override
    public void paint(Graphics g) {
        super.paint(g);
        g.drawImage(background,0,0,null);
        if (mySnake.live){
            mySnake.draw(g);
            if (food.live){
                food.draw(g);
                food.eaten(mySnake);
            }else {
                food = new Food();
            }
        }else {
            //失败场景
        }
        drawScore(g);
    }

    private void drawScore(Graphics g) {
        g.setFont(new Font(Font.SANS_SERIF,Font.BOLD,30));
        g.setColor(Color.MAGENTA);
        g.drawString("SCORE : "+mySnake.score,20,40);
    }

    public static void main(String[] args) {
        new Play().loadFrame();
    }
}
